package com.example.myapplication

import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.Button
import android.widget.TextView
import com.example.myapplication.databinding.ActivityMainBinding
import com.example.myapplication.databinding.ActivityMainBinding.inflate


class MainActivity : AppCompatActivity() {
    var count=0
    @SuppressLint("SetTextI18n")
    private lateinit var binding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        setContentView(R.layout.activity_main)
        binding = ActivityMainBinding.inflate(layoutInflater)
        val button1=binding.button1
        val button2=binding.button2;
        val view1=binding.linearLayout1
        val view2=binding.linearLayout2
        val view=binding.root
        val spinner=binding.spinner
        val expert= Language()
        setContentView(view)//必要部分当其设置为binding为根页面时

        button1.setOnClickListener{
            count++;
            val textView=TextView(this)
            textView.text=getString(R.string.text)+"$count"
            view1.addView(textView)
        }
        button2.setOnClickListener{
            val textView2=TextView(this)
            textView2.text=spinner.selectedItem.toString()+"    "+expert.getLanguage(spinner.selectedItem.toString())
            view2.addView(textView2)
        }

//        val button1=findViewById<Button>(R.id.button2)
//        button1.setOnClickListener(){
//           val textView=TextView(this)
//            textView.text= getString(R.string.text)+"$count"
//
//        }
    }
}